home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / styles / StyleManagerImpl.as < prev    next >
Text File  |  2009-02-12  |  15KB  |  498 lines

  1. package mx.styles
  2. {
  3.    import flash.events.IEventDispatcher;
  4.    import flash.events.TimerEvent;
  5.    import flash.system.ApplicationDomain;
  6.    import flash.system.SecurityDomain;
  7.    import flash.utils.Timer;
  8.    import mx.core.FlexVersion;
  9.    import mx.core.mx_internal;
  10.    import mx.events.ModuleEvent;
  11.    import mx.events.StyleEvent;
  12.    import mx.managers.SystemManagerGlobals;
  13.    import mx.modules.IModuleInfo;
  14.    import mx.modules.ModuleManager;
  15.    import mx.resources.IResourceManager;
  16.    import mx.resources.ResourceManager;
  17.    
  18.    use namespace mx_internal;
  19.    
  20.    public class StyleManagerImpl implements IStyleManager2
  21.    {
  22.       
  23.       private static var parentSizeInvalidatingStyles:Object = {
  24.          "bottom":true,
  25.          "horizontalCenter":true,
  26.          "left":true,
  27.          "right":true,
  28.          "top":true,
  29.          "verticalCenter":true,
  30.          "baseline":true
  31.       };
  32.       
  33.       private static var colorNames:Object = {
  34.          "transparent":"transparent",
  35.          "black":0,
  36.          "blue":255,
  37.          "green":32768,
  38.          "gray":8421504,
  39.          "silver":12632256,
  40.          "lime":65280,
  41.          "olive":8421376,
  42.          "white":16777215,
  43.          "yellow":16776960,
  44.          "maroon":8388608,
  45.          "navy":128,
  46.          "red":16711680,
  47.          "purple":8388736,
  48.          "teal":32896,
  49.          "fuchsia":16711935,
  50.          "aqua":65535,
  51.          "magenta":16711935,
  52.          "cyan":65535,
  53.          "halogreen":8453965,
  54.          "haloblue":40447,
  55.          "haloorange":16758272,
  56.          "halosilver":11455193
  57.       };
  58.       
  59.       private static var inheritingTextFormatStyles:Object = {
  60.          "align":true,
  61.          "bold":true,
  62.          "color":true,
  63.          "font":true,
  64.          "indent":true,
  65.          "italic":true,
  66.          "size":true
  67.       };
  68.       
  69.       private static var instance:IStyleManager2;
  70.       
  71.       private static var parentDisplayListInvalidatingStyles:Object = {
  72.          "bottom":true,
  73.          "horizontalCenter":true,
  74.          "left":true,
  75.          "right":true,
  76.          "top":true,
  77.          "verticalCenter":true,
  78.          "baseline":true
  79.       };
  80.       
  81.       mx_internal static const VERSION:String = "3.0.0.0";
  82.       
  83.       private static var sizeInvalidatingStyles:Object = {
  84.          "borderStyle":true,
  85.          "borderThickness":true,
  86.          "fontAntiAliasType":true,
  87.          "fontFamily":true,
  88.          "fontGridFitType":true,
  89.          "fontSharpness":true,
  90.          "fontSize":true,
  91.          "fontStyle":true,
  92.          "fontThickness":true,
  93.          "fontWeight":true,
  94.          "headerHeight":true,
  95.          "horizontalAlign":true,
  96.          "horizontalGap":true,
  97.          "kerning":true,
  98.          "leading":true,
  99.          "letterSpacing":true,
  100.          "paddingBottom":true,
  101.          "paddingLeft":true,
  102.          "paddingRight":true,
  103.          "paddingTop":true,
  104.          "strokeWidth":true,
  105.          "tabHeight":true,
  106.          "tabWidth":true,
  107.          "verticalAlign":true,
  108.          "verticalGap":true
  109.       };
  110.        
  111.       
  112.       private var _stylesRoot:Object;
  113.       
  114.       private var _selectors:Object;
  115.       
  116.       private var styleModules:Object;
  117.       
  118.       private var _inheritingStyles:Object;
  119.       
  120.       private var resourceManager:IResourceManager;
  121.       
  122.       private var _typeSelectorCache:Object;
  123.       
  124.       public function StyleManagerImpl()
  125.       {
  126.          _selectors = {};
  127.          styleModules = {};
  128.          resourceManager = ResourceManager.getInstance();
  129.          _inheritingStyles = {};
  130.          _typeSelectorCache = {};
  131.          super();
  132.       }
  133.       
  134.       public static function getInstance() : IStyleManager2
  135.       {
  136.          if(!instance)
  137.          {
  138.             instance = new StyleManagerImpl();
  139.          }
  140.          return instance;
  141.       }
  142.       
  143.       public function setStyleDeclaration(param1:String, param2:CSSStyleDeclaration, param3:Boolean) : void
  144.       {
  145.          ++param2.selectorRefCount;
  146.          _selectors[param1] = param2;
  147.          typeSelectorCache = {};
  148.          if(param3)
  149.          {
  150.             styleDeclarationsChanged();
  151.          }
  152.       }
  153.       
  154.       public function registerParentDisplayListInvalidatingStyle(param1:String) : void
  155.       {
  156.          parentDisplayListInvalidatingStyles[param1] = true;
  157.       }
  158.       
  159.       public function getStyleDeclaration(param1:String) : CSSStyleDeclaration
  160.       {
  161.          var _loc2_:int = 0;
  162.          if(param1.charAt(0) != ".")
  163.          {
  164.             _loc2_ = param1.lastIndexOf(".");
  165.             if(_loc2_ != -1)
  166.             {
  167.                param1 = param1.substr(_loc2_ + 1);
  168.             }
  169.          }
  170.          return _selectors[param1];
  171.       }
  172.       
  173.       public function set typeSelectorCache(param1:Object) : void
  174.       {
  175.          _typeSelectorCache = param1;
  176.       }
  177.       
  178.       public function isColorName(param1:String) : Boolean
  179.       {
  180.          return colorNames[param1.toLowerCase()] !== undefined;
  181.       }
  182.       
  183.       public function set inheritingStyles(param1:Object) : void
  184.       {
  185.          _inheritingStyles = param1;
  186.       }
  187.       
  188.       public function getColorNames(param1:Array) : void
  189.       {
  190.          var _loc4_:uint = 0;
  191.          if(!param1)
  192.          {
  193.             return;
  194.          }
  195.          var _loc2_:int = param1.length;
  196.          var _loc3_:int = 0;
  197.          while(_loc3_ < _loc2_)
  198.          {
  199.             if(param1[_loc3_] != null && isNaN(param1[_loc3_]))
  200.             {
  201.                if((_loc4_ = getColorName(param1[_loc3_])) != StyleManager.NOT_A_COLOR)
  202.                {
  203.                   param1[_loc3_] = _loc4_;
  204.                }
  205.             }
  206.             _loc3_++;
  207.          }
  208.       }
  209.       
  210.       public function isInheritingTextFormatStyle(param1:String) : Boolean
  211.       {
  212.          return inheritingTextFormatStyles[param1] == true;
  213.       }
  214.       
  215.       public function registerParentSizeInvalidatingStyle(param1:String) : void
  216.       {
  217.          parentSizeInvalidatingStyles[param1] = true;
  218.       }
  219.       
  220.       public function registerColorName(param1:String, param2:uint) : void
  221.       {
  222.          colorNames[param1.toLowerCase()] = param2;
  223.       }
  224.       
  225.       public function isParentSizeInvalidatingStyle(param1:String) : Boolean
  226.       {
  227.          return parentSizeInvalidatingStyles[param1] == true;
  228.       }
  229.       
  230.       public function registerInheritingStyle(param1:String) : void
  231.       {
  232.          inheritingStyles[param1] = true;
  233.       }
  234.       
  235.       public function set stylesRoot(param1:Object) : void
  236.       {
  237.          _stylesRoot = param1;
  238.       }
  239.       
  240.       public function get typeSelectorCache() : Object
  241.       {
  242.          return _typeSelectorCache;
  243.       }
  244.       
  245.       public function isParentDisplayListInvalidatingStyle(param1:String) : Boolean
  246.       {
  247.          return parentDisplayListInvalidatingStyles[param1] == true;
  248.       }
  249.       
  250.       public function isSizeInvalidatingStyle(param1:String) : Boolean
  251.       {
  252.          return sizeInvalidatingStyles[param1] == true;
  253.       }
  254.       
  255.       public function styleDeclarationsChanged() : void
  256.       {
  257.          var _loc4_:Object = null;
  258.          var _loc1_:Array = SystemManagerGlobals.topLevelSystemManagers;
  259.          var _loc2_:int = _loc1_.length;
  260.          var _loc3_:int = 0;
  261.          while(_loc3_ < _loc2_)
  262.          {
  263.             (_loc4_ = _loc1_[_loc3_]).regenerateStyleCache(true);
  264.             _loc4_.notifyStyleChangeInChildren(null,true);
  265.             _loc3_++;
  266.          }
  267.       }
  268.       
  269.       public function isValidStyleValue(param1:*) : Boolean
  270.       {
  271.          return param1 !== undefined;
  272.       }
  273.       
  274.       public function loadStyleDeclarations(param1:String, param2:Boolean = true, param3:Boolean = false) : IEventDispatcher
  275.       {
  276.          return loadStyleDeclarations2(param1,param2);
  277.       }
  278.       
  279.       public function get inheritingStyles() : Object
  280.       {
  281.          return _inheritingStyles;
  282.       }
  283.       
  284.       public function unloadStyleDeclarations(param1:String, param2:Boolean = true) : void
  285.       {
  286.          var _loc4_:IModuleInfo = null;
  287.          var _loc3_:StyleModuleInfo = styleModules[param1];
  288.          if(_loc3_)
  289.          {
  290.             _loc3_.styleModule.unload();
  291.             (_loc4_ = _loc3_.module).unload();
  292.             _loc4_.removeEventListener(ModuleEvent.READY,_loc3_.readyHandler);
  293.             _loc4_.removeEventListener(ModuleEvent.ERROR,_loc3_.errorHandler);
  294.             styleModules[param1] = null;
  295.          }
  296.          if(param2)
  297.          {
  298.             styleDeclarationsChanged();
  299.          }
  300.       }
  301.       
  302.       public function getColorName(param1:Object) : uint
  303.       {
  304.          var _loc2_:Number = NaN;
  305.          var _loc3_:* = undefined;
  306.          if(param1 is String)
  307.          {
  308.             if(param1.charAt(0) == "#")
  309.             {
  310.                _loc2_ = Number("0x" + param1.slice(1));
  311.                return !!isNaN(_loc2_) ? uint(StyleManager.NOT_A_COLOR) : uint(uint(_loc2_));
  312.             }
  313.             if(param1.charAt(1) == "x" && param1.charAt(0) == "0")
  314.             {
  315.                _loc2_ = Number(param1);
  316.                return !!isNaN(_loc2_) ? uint(StyleManager.NOT_A_COLOR) : uint(uint(_loc2_));
  317.             }
  318.             _loc3_ = colorNames[param1.toLowerCase()];
  319.             if(_loc3_ === undefined)
  320.             {
  321.                return StyleManager.NOT_A_COLOR;
  322.             }
  323.             return uint(_loc3_);
  324.          }
  325.          return uint(param1);
  326.       }
  327.       
  328.       public function isInheritingStyle(param1:String) : Boolean
  329.       {
  330.          return inheritingStyles[param1] == true;
  331.       }
  332.       
  333.       public function get stylesRoot() : Object
  334.       {
  335.          return _stylesRoot;
  336.       }
  337.       
  338.       public function initProtoChainRoots() : void
  339.       {
  340.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  341.          {
  342.             delete _inheritingStyles["textDecoration"];
  343.             delete _inheritingStyles["leading"];
  344.          }
  345.          if(!stylesRoot)
  346.          {
  347.             stylesRoot = _selectors["global"].addStyleToProtoChain({},null);
  348.          }
  349.       }
  350.       
  351.       public function loadStyleDeclarations2(param1:String, param2:Boolean = true, param3:ApplicationDomain = null, param4:SecurityDomain = null) : IEventDispatcher
  352.       {
  353.          var module:IModuleInfo = null;
  354.          var styleEventDispatcher:StyleEventDispatcher = null;
  355.          var timer:Timer = null;
  356.          var timerHandler:Function = null;
  357.          var url:String = param1;
  358.          var update:Boolean = param2;
  359.          var applicationDomain:ApplicationDomain = param3;
  360.          var securityDomain:SecurityDomain = param4;
  361.          module = ModuleManager.getModule(url);
  362.          var readyHandler:Function = function(param1:ModuleEvent):void
  363.          {
  364.             var _loc2_:IStyleModule = IStyleModule(param1.module.factory.create());
  365.             styleModules[param1.module.url].styleModule = _loc2_;
  366.             if(update)
  367.             {
  368.                styleDeclarationsChanged();
  369.             }
  370.          };
  371.          module.addEventListener(ModuleEvent.READY,readyHandler,false,0,true);
  372.          styleEventDispatcher = new StyleEventDispatcher(module);
  373.          var errorHandler:Function = function(param1:ModuleEvent):void
  374.          {
  375.             var _loc3_:StyleEvent = null;
  376.             var _loc2_:String = resourceManager.getString("styles","unableToLoad",[param1.errorText,url]);
  377.             if(styleEventDispatcher.willTrigger(StyleEvent.ERROR))
  378.             {
  379.                _loc3_ = new StyleEvent(StyleEvent.ERROR,param1.bubbles,param1.cancelable);
  380.                _loc3_.bytesLoaded = 0;
  381.                _loc3_.bytesTotal = 0;
  382.                _loc3_.errorText = _loc2_;
  383.                styleEventDispatcher.dispatchEvent(_loc3_);
  384.                return;
  385.             }
  386.             throw new Error(_loc2_);
  387.          };
  388.          module.addEventListener(ModuleEvent.ERROR,errorHandler,false,0,true);
  389.          styleModules[url] = new StyleModuleInfo(module,readyHandler,errorHandler);
  390.          timer = new Timer(0);
  391.          timerHandler = function(param1:TimerEvent):void
  392.          {
  393.             timer.removeEventListener(TimerEvent.TIMER,timerHandler);
  394.             timer.stop();
  395.             module.load(applicationDomain,securityDomain);
  396.          };
  397.          timer.addEventListener(TimerEvent.TIMER,timerHandler,false,0,true);
  398.          timer.start();
  399.          return styleEventDispatcher;
  400.       }
  401.       
  402.       public function registerSizeInvalidatingStyle(param1:String) : void
  403.       {
  404.          sizeInvalidatingStyles[param1] = true;
  405.       }
  406.       
  407.       public function clearStyleDeclaration(param1:String, param2:Boolean) : void
  408.       {
  409.          var _loc3_:CSSStyleDeclaration = getStyleDeclaration(param1);
  410.          if(_loc3_ && _loc3_.selectorRefCount > 0)
  411.          {
  412.             --_loc3_.selectorRefCount;
  413.          }
  414.          delete _selectors[param1];
  415.          if(param2)
  416.          {
  417.             styleDeclarationsChanged();
  418.          }
  419.       }
  420.       
  421.       public function get selectors() : Array
  422.       {
  423.          var _loc2_:* = null;
  424.          var _loc1_:Array = [];
  425.          for(_loc2_ in _selectors)
  426.          {
  427.             _loc1_.push(_loc2_);
  428.          }
  429.          return _loc1_;
  430.       }
  431.    }
  432. }
  433.  
  434. import flash.events.EventDispatcher;
  435. import mx.events.ModuleEvent;
  436. import mx.events.StyleEvent;
  437. import mx.modules.IModuleInfo;
  438.  
  439. class StyleEventDispatcher extends EventDispatcher
  440. {
  441.     
  442.    
  443.    function StyleEventDispatcher(param1:IModuleInfo)
  444.    {
  445.       super();
  446.       param1.addEventListener(ModuleEvent.ERROR,moduleInfo_errorHandler,false,0,true);
  447.       param1.addEventListener(ModuleEvent.PROGRESS,moduleInfo_progressHandler,false,0,true);
  448.       param1.addEventListener(ModuleEvent.READY,moduleInfo_readyHandler,false,0,true);
  449.    }
  450.    
  451.    private function moduleInfo_progressHandler(param1:ModuleEvent) : void
  452.    {
  453.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.PROGRESS,param1.bubbles,param1.cancelable);
  454.       _loc2_.bytesLoaded = param1.bytesLoaded;
  455.       _loc2_.bytesTotal = param1.bytesTotal;
  456.       dispatchEvent(_loc2_);
  457.    }
  458.    
  459.    private function moduleInfo_readyHandler(param1:ModuleEvent) : void
  460.    {
  461.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.COMPLETE);
  462.       dispatchEvent(_loc2_);
  463.    }
  464.    
  465.    private function moduleInfo_errorHandler(param1:ModuleEvent) : void
  466.    {
  467.       var _loc2_:StyleEvent = new StyleEvent(StyleEvent.ERROR,param1.bubbles,param1.cancelable);
  468.       _loc2_.bytesLoaded = param1.bytesLoaded;
  469.       _loc2_.bytesTotal = param1.bytesTotal;
  470.       _loc2_.errorText = param1.errorText;
  471.       dispatchEvent(_loc2_);
  472.    }
  473. }
  474.  
  475. import mx.modules.IModuleInfo;
  476. import mx.styles.IStyleModule;
  477.  
  478. class StyleModuleInfo
  479. {
  480.     
  481.    
  482.    public var errorHandler:Function;
  483.    
  484.    public var readyHandler:Function;
  485.    
  486.    public var module:IModuleInfo;
  487.    
  488.    public var styleModule:IStyleModule;
  489.    
  490.    function StyleModuleInfo(param1:IModuleInfo, param2:Function, param3:Function)
  491.    {
  492.       super();
  493.       this.module = param1;
  494.       this.readyHandler = param2;
  495.       this.errorHandler = param3;
  496.    }
  497. }
  498.